<template>
  <div class="reportchartsTimeAllSex" style="height: 580px;">
<!--    <h2>分时-合计报表</h2>-->
    <div class="con">
      <div
        class="repecharts"
        :id="timeId"
      ></div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
  .reportchartsTimeAllSex {
    width: 100%;
    background: #fff;
    overflow: hidden;
    > h2 {
      line-height: 1;
      font-weight: 600;
      font-size: 20px;
      letter-spacing: 1px;
    }
    .echardiv{
      width: 100%;
      height: 420px;
    }
    .repecharts {
      width: 100%;
      height: 580px;
    }
    .con {
      position: relative;
      margin-top: 10px;
      .el-tabs {
        overflow: inherit;
        .el-tabs__header {
          width: 85px;
          .el-tabs__item {
            span {
              font-size: 16px;
              i {
                margin-right: 8px;
              }
            }
          }
        }
        .el-tabs__content {
          overflow: inherit;
          .tab-block{
            display: none!important;
          }
        }
      }
      .kpi{
        position: absolute;
        top: -45px;
        right:0;
        margin-right: 60px;
      }
      .kpis {
        position: absolute;
        left: 210px;
        top: -45px;
      }
    }
    .timeoption {
      position: absolute;
      right: 0;
      top: -55px;
      .on {
        .el-input--suffix {
          .el-input__inner {
            color: #e8eeff;
            background: #5580ff;
          }
        }
      }
      margin-right: 60px;
      line-height: 48px;
      label {
        font-size: 18px;
        vertical-align: top;
      }
      .el-select {
        display: inline-block;
        margin-left: 5px;
        width: 72px;
        height: 30px;
        .el-input__inner {
          box-sizing: border-box;
          height: 32px;
          text-align: center;
          padding: 0 18px 0 0;
          width: 100%;
          font-size: 14px;
        }
        .el-input {
          position: relative;
          z-index: 9;

          .el-input__suffix {
            .el-input__suffix-inner {
              line-height: 100%;
              display: inline-block;
            }
            right: 0;
            span {
              .el-select__caret {
                font-size: 12px;
                color: #8ba9ff;
              }
            }
          }
        }
      }
      .timebtn {
        float: right;
        display: block;
        height: 100%;
        padding-top: 10px;
        //margin-left: -3px;
        a,
        .el-radio {
          border: 1px solid #dbe1e5;
          border-left: none;
          margin: 0 !important;
          float: left;
          height: 30px;
          line-height: 30px;
          color: #737373;
          font-size: 14px;
          padding: 0 18px;
          cursor: pointer;
          .el-radio__input {
            display: none;
          }
          .el-radio__label {
            padding: 0;
            line-height: 30px;
          }
          &.on,
          &.is-checked {
            color: #e8eeff !important;
            .el-radio__label {
              color: #e8eeff;
            }
            background: #5580ff !important;
          }
          &:first-child {
            border-left: 1px solid #dbe1e5;
            border-radius: 5px 0 0 5px;
          }
          &:last-child {
            border-radius: 0 5px 5px 0;
          }
          &:hover {
            background: #ebebeb;
            color: #333;
            opacity: 0.9;
          }
        }
      }
    }
  }
</style>
<script>
  let echarts = require("echarts");
  let moment = require("moment");
  import reportGlobal from "@/components/global/reportGlobal";//公共配置
  let unit = reportGlobal.unit;
  let colorList = reportGlobal.colorList;
  export default {
    props: {
      con_w:{
        default:function () {
          return ''
        }
      }
    },
    data() {
      return {
        Echarts:null,
        timeId:
          Number(
            Math.random()
            .toString()
            .substr(3, 15) + Date.now()
          ).toString(36) + "Echarts",
        defaultEcharts:{            //默认样式与无数据图片
          title:{
            show:true,
            text:"暂 无 数 据",
            textAlign:'center',
            left:'48%',
            top:'45%',
            textStyle:{
              fontSize:16,
              color:'#b4b6bd',
            }
          },
          grid: {
            x: 70,
            x2: "8%"
          },
          backgroundColor:{
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
              offset: 0, color: '#f5f8fe' // 0% 处的颜色
            }
            ],
            global: false // 缺省为 false
          },

          series: []
        },
        kpiCheckType:[],
        option:{
          title:{
            text:'全部人脸数据-男女比例分布',
            textStyle:{
              fontSize: '22',
              fontWeight:'bold',
              color:'#121212'
            },
            top:'0',
            left:'center'
          },
          legend:{
            type: 'scroll',
            orient: "horizontal",
            width:'80%',
            top: "30px",
            left:'center',
            itemGap: 20,
          },
          grid:{
            left:'100',
            right:'80',
            top:'70',
            bottom:100,
          },
          toolbox:{
            right: "30",
            top: "0",
            feature: {
              saveAsImage: { show: true }
            }
          },
          tooltip:{
            trigger: "axis",
            axisPointer: {
              // 坐标轴指示器，坐标轴触发有效
              type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            },
            formatter: function(params) {
              //自定义函数修改折线图给数据加单位
              let str = ""; //声明一个变量用来存储数据
              str += "<div>" + params[0].name + "</div>"; //显示日期的函数
              for (let i = 0; i < params.length; i++) {
                //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                str +=
                  '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' +
                  params[i].color +
                  ';"></span>' +
                  params[i].seriesName +
                  "</span> : <span>" +
                  (params[i].seriesName.includes('率')
                    ? params[i].data + "%"
                    : params[i].data) +
                  "</br>";
              }
              return str;
            }
          },
          nameLocation:'center',
          dataZoom:[
            {
              show: true,
              start: 0,
              end: 100,
              height: 30,
            },
            {
              type: 'slider',
              start: 0,
              end: 100,
            }
          ],
          yAxis:   {
            type: "value",
            name: '',
            axisLine: {
              lineStyle: {
                color: '#2c69f3'
              }
            },
          },
          xAxis:[],
          series:[],
        },
        isUpData:false,
        sexColor:{
          face_total_enters:['#6e9aff','#2c69f3'],
          face_member_enters:['#ffd196','#ff9f23'],
          face_repeats_enters:['#ff6d8f','#e70036'],
        },
        record:'',          //记录指标点击为最后一个值
      };
    },
    components: {},
    created() {},
    mounted() {
      //默认分时
      this.Echarts = echarts.init(document.getElementById(this.timeId));
      this.defaultEchart();
      setTimeout(() => {
        this.loadEchartResize("");
      }, 200);
    },
    beforeDestroy(){},
    watch: {
      con_w(val){
        this.loadEchartResize(val);
      }
    },
    methods: {
      UpData(data){
        if(!data){
          return
        }
        if(!this.option.xAxis.length){
          this.option.xAxis.push({
            type: "category",
            gridIndex: 0,
            axisLabel: {
              rotate: 30
            },
            data:data.x_data
          })
        }

        let maleSerObj = {
          type: "bar",
          name: data.y_name + '(男)',
          stack: data.key,
          color:this.sexColor[data.key][1],
          barMaxWidth: '20px',
          data: data.y_data_male,
          itemStyle: {
            normal: {
              borderColor:'#fff',
              borderWidth:1,
            }
          },
        };
        let femaleSerObj = {
          type: "bar",
          name: data.y_name + '(女)',
          stack: data.key,
          color:this.sexColor[data.key][0],
          barMaxWidth: '20px',
          data: data.y_data_female,
        };
        this.option.series.push(femaleSerObj);
        this.option.series.push(maleSerObj);

        if(this.isUpData){
          this.Echarts.setOption(this.option);
        }else{
          this.isUpData = true
          this.Echarts.setOption(this.option,true);
        }
      },
      //设置成默认状态
      defaultEchart() {
        this.isUpData = false;
        this.option.xAxis = [];
        this.option.series = [];
        this.Echarts.setOption(this.defaultEcharts,true);
      },
      loadEchartResize(w) {
        let opts = { width: (w - 20) };
        this.Echarts.resize(opts);
      },

    },
  };
</script>
